package web.servlet.request.SorryServlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: 18148
 * @Date: 2020-05-15 15:16:24
 */
@WebServlet("/sorryServlet")
public class SorryServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String referer = req.getHeader("referer");
        String path = req.getContextPath();
        if (referer!= null) {
            if (referer.contains(path)) {
                System.out.println("可以访问");
                RequestDispatcher requestDispatcher = req.getRequestDispatcher("/homework/sorryServlet.html");
                requestDispatcher.forward(req,resp);
            }
            else  {
                RequestDispatcher requestDispatcher = req.getRequestDispatcher("/homework/forwardSorry.html");
                requestDispatcher.forward(req,resp);
            }
        }
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
